import axios from "axios"


const instance = axios.create({
    baseURL:'https://www.fastmock.site/mock/ae8e9031947a302fed5f92425995aa19/jd',
    timeout:10000
}); 


instance.interceptors.response.use(
    response => {
       if(response.status === 200 && response.data){
            // console.log(response.data);
            return response.data
       }else{
           return Promise.reject(new Error('请求失败'))
       }
    },
    error=>{
        return Promise.reject(error)
    }
)


export const get = (url,params = {}) => {
    return new Promise((reslove,reject) => {
        instance.get(url,{ params }).then((response)=>{
            reslove(response.data)
        },err=>{
            reject(err)
        })
    })
}


export const post = (url,data = {}) => {
    return new Promise((reslove,reject) => {
        instance.post(url,data,{
            headers:{
                'Content-Type': "application/json"
            }
        }).then((response)=>{
            reslove(response.data)
        },err=>{
            reject(err)
        })
    })
}